package org.shj.pattern.composite

import scala.collection.mutable.ArrayBuffer

abstract class Component(name: String) {
  def add(comp: Component)
  
  def remove(comp: Component)
  
  def show(depth: Int)
}

class Company(name: String) extends Component(name: String){
  val departments = new ArrayBuffer[Component]()
  
  def add(comp: Component){
    departments += comp
  }
  
  def remove(comp: Component){
    departments -= comp
  }
  
  def show(depth: Int){
    for(i <- 0 to depth){
      print("--")
    }
    
    println(name)
    departments.foreach(_.show(depth + 1))
  }
}

class Department(name: String) extends Component(name: String){
  def add(comp: Component){
    println("cannot add")
  }
  
  def remove(comp: Component){
    println("cannot remove")
  }
  
  def show(depth: Int){
    for(i <- 0 to depth){
      print("--")
    }    
    println(name)
  }
}
